#include <ESP8266WiFi.h>

const char* ssid = "bill";
const char* password = "12345678";

IPAddress softLocal(192,168,5,9); //IP  
IPAddress softGateway(192,168,5,1); //网关
IPAddress softSubnet(255,255,255,0); //子网掩码

WiFiServer server(2001); //设置server监听端口

void setup()
{
    Serial.begin(9600);
    
    Serial.print("Setting AP...");
    WiFi.softAPConfig(softLocal, softGateway, softSubnet);  
    WiFi.softAP(ssid, password); //启动AP
    //Serial.println("ServerAddress: " + WiFi.softAPIP());
    server.begin(); //启动监听
    server.setNoDelay(true);
}

void loop()
{
    WiFiClient client = server.available();
    if (client)
    {
        Serial.println("\n[Client connected]");
        while (client.connected())
        {
            if (client.available())//client数据转发到串口
            {
                uint8_t dataFromClient = client.read();
                Serial.write(dataFromClient);
            }
            if(Serial.available())//串口数据转发到client
            {
                size_t count = Serial.available();
                uint8_t revBuf[count];
                Serial.readBytes(revBuf, count);
                client.write(revBuf, count);
            }
        }       
    }
}
